//
//  ShakePushTransition.m
//  HuoBao
//
//  Created by chaiyanan on 15/12/11.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "ShakePushTransition.h"

@implementation ShakePushTransition

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 0.5f;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    
    CGRect finalFrameForVc = [transitionContext finalFrameForViewController:toVC];
    //    CGRect bounds = [UIScreen mainScreen].bounds;
    //    toVC.view.frame = CGRectOffset(finalFrameForVc, 0, bounds.size.height);
    toVC.view.frame = CGRectMake(self.orginPoint.x, self.orginPoint.y, 10, 10);
    toVC.view.alpha = 0.3;
    [[transitionContext containerView]addSubview:toVC.view];
    
    [UIView animateWithDuration:[self transitionDuration:transitionContext]
                          delay:0.0
//         usingSpringWithDamping:0.5 
//          initialSpringVelocity:0.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         fromVC.view.alpha = 0.8;
                         toVC.view.frame = finalFrameForVc;
                         toVC.view.alpha = 1.0f;
                         
                     } completion:^(BOOL finished) {
                         [transitionContext completeTransition:YES];
                         fromVC.view.alpha = 1.0;
                     }];
}

@end
